<?php
/**
 * Created by PhpStorm.
 * User: qishengqiang
 * Date: 2022-06-02
 * Time: 14:40
 */

namespace app\applet\controller;


use app\applet\BaseController;

class OrganizationController extends BaseController
{
    public function listsAction()
    {
        try {
            if (!$this->user) {
                throw new \Exception('请先登录', 401);
            }

            $params['where'][] = ['status', '=', 1];
            $params['where'][] = ['appletId', '=', $this->appletId];
            if (isset($this->get['organizationName'])) {
                $params['where'][] = ['organizationName', 'like', '%'.$this->get['organizationName'].'%'];
            }

            if (isset($this->get['categoryId'])) {
                $params['where'][] = ['categoryId', '=', $this->get['categoryId']];
            }

            $params['order'] = ['creditCountView' => 'desc'];

            $lists = $this->app->organizationService->getLists($params, $this->page, $this->pagesize);

            $data['lists'] = [];

            if (count($lists)) {
                foreach ($lists as $val) {
                    $data['lists'][] = [
                        'organizationId' => $val->organizationId,
                        'organizationName' => $val->organizationName,
                        'organizationLogo' => $val->organizationLogo,
                        'creditCountView' => $val->creditCountView,
                        'personCountView' => $val->personCountView,
                    ];
                }
            }

            $data['totalInfo'] = $this->app->utilService->getMeta($lists);

            return json(['code' => 200, 'msg' => '查询成功', 'data'=> $data]);

        } catch (\Exception $e) {
            return json(['code' => $e->getCode(), 'msg' => $e->getMessage(), 'data'=> []]);
        }
    }
}